<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理系统_登录</title>
<link rel="stylesheet" type="text/css" href="/styles/login.css" />
<script type="text/javascript" src="/scripts/jquery.min.js"></script>
<script>
	function getBytesLength(str) {
		return str.replace(/[^\x00-\xff]/g, 'xx').length;
	};
	function checkLogin() {
		$(".failure").text("");
		var lname = jQuery.trim($("#loginname").val());
		var lpwd = jQuery.trim($("#loginpwd").val());
		if (lname != '' & lpwd != '') {
			jQuery.ajax({
				url : '/login.json',
				type : 'POST',
				processData : true,
				data : {
					name : lname,
					pwd : lpwd
				},
				success : function(data) {
					if (data && data.ok) {
						var tourl = getUrlParam('tourl');
						if (tourl != null)
							location.href = tourl;
						else
							location.href = '/';
					} else {
						$(".failure").text("用户名或密码错误！");
						return false;
					}
				},
				error : function(e) {
					$(".failure").text("用户名或密码错误！");
					return false;
				}
			});
		} else {
			$(".failure").text("请输入用户名和密码！");
			return false;
		}
		return false;
	}

	function getUrlParam(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return null;
	}
</script>
</head>

<body>
  <div class="login">
    <div class="logo-title">
      <img src="template/images/logo.gif" border="0" />
      <h4>后台管理系统</h4>
    </div>
    <div class="form">
      <h4 class="title">操作员登录</h4>
      <div class="failure"></div>
      <form method="post" action="" id="">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="31%" height="35" align="right">用户名：<br /></td>
            <td width="69%"><input name="loginname" id="loginname" type="text"
              size="25" autofocus /></td>
          </tr>
          <tr>
            <td height="35" align="right">密 码：<br /></td>
            <td><input name="loginpwd" id="loginpwd" type="password" size="25" /></td>
          </tr>
          <tr>
            <td colspan="2" align="center" height="60"><input
              type="submit" name="btnLogin" id="btnLogin"
              onclick="return checkLogin();" value="登 录" class="btn" /></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</body>
</html>
